home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / samples / Multimedia / Media / Blend.vsh < prev    next >
Encoding:
Text File  |  2001-10-08  |  2.4 KB  |  88 lines

  1. vs.1.0
  2. ;------------------------------------------------------------------------------
  3. ; Constants specified by the app
  4. ;    c0      = (0,0,0,0)
  5. ;    c1      = (1,1,1,1)
  6. ;    c2      = (0,1,2,3)
  7. ;    c3      = (4,5,6,7)
  8. ;    c4-c7   = matWorld0
  9. ;    c8-c11  = matWorld1
  10. ;    c12-c15 = matViewProj
  11. ;    c20     = light direction
  12. ;    c21     = material diffuse color * light diffuse color
  13. ;    c22     = material ambient color
  14. ;
  15. ; Vertex components (as specified in the vertex DECL)
  16. ;    v0    = Position
  17. ;    v1.x  = Blend weight
  18. ;    v3    = Normal
  19. ;    v7    = Texcoords
  20. ;------------------------------------------------------------------------------
  21.  
  22.  
  23. ;------------------------------------------------------------------------------
  24. ; Vertex blending
  25. ;------------------------------------------------------------------------------
  26.  
  27. ; Transform position for world0 matrix
  28. dp4 r0.x, v0, c4
  29. dp4 r0.y, v0, c5
  30. dp4 r0.z, v0, c6
  31. dp4 r0.w, v0, c7
  32.  
  33. ; Transform position for world1 matrix
  34. dp4 r1.x, v0, c8
  35. dp4 r1.y, v0, c9
  36. dp4 r1.z, v0, c10
  37. dp4 r1.w, v0, c11
  38.  
  39. ; Lerp the two positions r0 and r1 into r2
  40. mul r0, r0, v1.x     ; v0 * weight
  41. add r2, c1.x, -v1.x  ; r2 = 1 - weight
  42. mad r2, r1, r2, r0   ; pos = (1-weight)*v1 + v0*weight
  43.  
  44. ; Transform to projection space
  45. dp4 oPos.x, r2, c12 
  46. dp4 oPos.y, r2, c13
  47. dp4 oPos.z, r2, c14
  48. dp4 oPos.w, r2, c15
  49.  
  50.  
  51. ;------------------------------------------------------------------------------
  52. ; Lighting calculation
  53. ;------------------------------------------------------------------------------
  54.  
  55. ; Transform normal for world0 matrix
  56. dp4 r0.x, v3, c4
  57. dp4 r0.y, v3, c5
  58. dp4 r0.z, v3, c6
  59. dp4 r0.w, v3, c7
  60.  
  61. ; Transform normal for world1 matrix
  62. dp4 r1.x, v3, c8
  63. dp4 r1.y, v3, c9
  64. dp4 r1.z, v3, c10
  65. dp4 r1.w, v3, c11
  66.  
  67. ; Lerp the two normals r0 and r1 into r2
  68. mul r0, r0, v1.x     ; v0 * weight
  69. add r2, c1.x, -v1.x  ; r2 = 1 - weight
  70. mad r2, r1, r2, r0   ; normal = (1-weight)*v1 + v0*weight
  71.  
  72. ; Do the lighting calculation
  73. dp3 r1.x, r2, c20    ; r1 = normal dot light
  74. max r1, r1.x, c0     ; if dot < 0 then dot = 0
  75. mul r0, r1.x, c21    ; Multiply with diffuse
  76. add r0, r0, c22      ; Add in ambient
  77. min oD0, r0, c1.x    ; clamp if > 1
  78.  
  79.  
  80. ;------------------------------------------------------------------------------
  81. ; Texture coordinates
  82. ;------------------------------------------------------------------------------
  83.  
  84. ; Just copy the texture coordinates
  85. mov oT0,  v7
  86.  
  87.  
  88.